<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <ul>

    </ul>
    <script src="./js/axios.js"></script>
    <script>
         let id = localStorage.getItem("xid");
        console.log(id);
        async function loadList1() {
              let url = "http://jx.xuzhixiang.top/ap/api/detail.php";
              let r = await axios.get(url, { params:  { pagesize: 20, pagenum: 0, id } });
              console.log(r.data);
              let pObj = r.data.data;
        let str = `
                <h1 style="color:#000">${pObj.pname}</h1>
                <img src="${pObj.pimg}" alt="">
                <p style="color:#f00">${pObj.pprice}</p>
                <p style="color:#000">${pObj.pdesc}</p>
            <input type="number" value="1" min="1" class="pnum">
            <button onclick="Addshoppingcart()" style="color:red;border-radius:10px">加入购物车</button>
        `;
        document.querySelector("ul").innerHTML = str;
      };
            
            loadList1();
            function Addshoppingcart(){
                let uid = localStorage.getItem("id");
        let pid = id;
        // 获取数量框
        let pnum = document.querySelector(".pnum").value;
        //

        let url = "http://jx.xuzhixiang.top/ap/api/add-product.php";
        axios.get(url, { params: { uid, pid, pnum } }).then((r) => {
          console.log(r.data);
          alert("添加至购物车成功");
          location.href = "cart.html";
        });
            }
    </script>
</body>
</html>